package com.example.wisdommanufactor.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;

public abstract class BaseFragment extends SwipeBackFragment {
    // 用以设置fragment的layout
    public abstract Object setLayout();
    // 用于在自己的fragment中绑定layout中的控件
    public abstract void onBindView(@Nullable Bundle saveInstanceState, View rootView);

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View rootView = null;
        if(setLayout() instanceof Integer){
            rootView = inflater.inflate((Integer)setLayout(),container,false);
        }else if(setLayout() instanceof View){
            rootView = (View) setLayout();
        }else{
            throw new ClassCastException("type must be int or view");
        }
        onBindView(savedInstanceState,rootView);
        return rootView;
    }

}
